﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;
using Entidad;
using System.Text.RegularExpressions;
public partial class IniciarSesion : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    bool IsValidLoginName(string strIn)
    {
        // Return true if strIn is in valid e-mail format.

        return Regex.IsMatch(strIn, @"\d+");
    }

    protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
    {
        if (!IsValidLoginName(Login1.UserName))
        {
            Login1.InstructionText = "Ingrese un usuario valido...(solo numeros)";
            Login1.InstructionTextStyle.ForeColor = System.Drawing.Color.RosyBrown;
            e.Cancel = true;
        }
        else
        {
            Login1.InstructionText = String.Empty;
        }

    }
    protected void Login1_LoginError(object sender, EventArgs e)
    {

        //Login1.HelpPageText = "Ta mal locoo...";
        //Login1.PasswordRecoveryText = "Forgot your password?";
        Login1.FailureText = "Usuario o Contraseña incorrecta";
    }

    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
 
        if (GestorUsuarios.VerificarUsuarioClave(int.Parse(Login1.UserName), Login1.Password))
        {
            Session["NombreUsuario"] = GestorUsuarios.ObtenerNombre(int.Parse(Login1.UserName));
            e.Authenticated = true;  // genera cookie de seguridad con datos del usuario 
        }
        else
        {
            e.Authenticated = false;
        }
    }

  
}

